﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

namespace ecommerceSample
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ViewState["LoginErrors"] = 0;
            }
        }

        protected void login2_Authenticate(object sender, AuthenticateEventArgs e)
        {
            if (Membership.ValidateUser(login2.UserName, login2.Password))
            {
                e.Authenticated = true;
                Session["ActualUser"] = login2.UserName;
                
            }
            else
            {
                e.Authenticated = false;
            }
        }

        protected void login2_LoginError(object sender, EventArgs e)
        {

            int errorCount = (int)ViewState["LoginErrors"] + 1;
            ViewState["LoginErrors"] = errorCount;
            if (errorCount > 3)
            {
                Response.Redirect(login2.PasswordRecoveryUrl);
            }
        }
    }
}